<?php
/**
 * 飞信机器人--功能插件--基类
 * 功能：所有插件，可以继承该类
 * 数据表：无
 * 作者： Kelvin
 * 联系： msn:shichangguo@msn.com, qq:191848423
*/
class CommonPlugin
{
	var $session;
	var $pid;
	var $extraParam;
	var $admin=array();
	var $UUID;
	
	function __construct(&$session, $pid, $extraPara="")
	{
		$this->session = &$session;
		$this->pid = $pid;
		parse_str($extraPara, $this->extraParam);
		$this->admin = explode(",",$this->extraParam['admin']);
	}
	
	function CommonPlugin(&$session, $pid, $extraPara="")
	{
		$this->session = &$session;
		$this->pid = $pid;
		parse_str($extraPara, $this->extraParam);
	}
	
	public function isAdmin()
	{
		for($i=0; $i<count($this->admin); $i++)
		{
			if($this->admin[$i] == $this->session->buddyArray['sid'])return true;
		}
		return false;
	}
	
	function getFooter($extra="")
	{
		return "\n<Font Face='楷体' Color='-8388608' Size='10.5'>【m-返回主菜单,q-返回上一级{$extra}】</font>";
	}
	
	function backMain()
	{
		$this->session->set('NODE',0);
		$this->session->set('PLUGIN','');
	}
	function backUp()
	{
		$this->session->set('NODE',$this->pid);
		$this->session->set('PLUGIN','');		
	}
	
	function handleInput($input)
	{
		if( $input == 'm' )
		{
			$this->backMain();
			return true;
		}
		if( $input == 'q' )
		{
			$this->backUp();
			return true;
		}	
	}
	
	public function getTips()
	{
		return "尚未实现";
	}
	
	public function handle($input)
	{
		return "尚未实现";
	}
	
	public function getValue($key)
	{
		if(!isset($this->UUID) || empty($this->UUID))die('UUID Not set!');
		return $this->session->getValue("{$this->UUID}_{$key}");
	}
	public function getStr($key)
	{
		if(!isset($this->UUID) || empty($this->UUID))die('UUID Not set!');
		return $this->session->getStr("{$this->UUID}_{$key}");
	}
	public function set($key,$value)
	{
		if(!isset($this->UUID) || empty($this->UUID))die('UUID Not set!');
		return $this->session->set("{$this->UUID}_{$key}",$value);
	}
	public function query($sql)
	{
		return $this->session->db->fetchQueryAll($sql);
	}
	public function execute($sql)
	{
		return $this->session->db->execute($sql);
	}
	public function getBuddyID()
	{
		return $this->session->buddyID;
	}
}

?>